//
//  ProfileTopView.m
//  AILove
//
//  Created by 甘世清 on 2023/12/30.
//

#import "ProfileTopView.h"
#import "ProfileCollectionViewCell.h"
#import "JieSuoView.h"
#import "PeoplePhotoViewController.h"
@implementation ProfileTopView

- (void)SQ_UIViewForSelfView{
    [self addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(700);
    }];
    
    UILabel * label = [[UILabel alloc]init];
    label.text = SQNSLocalString(@"点击图标即可和我互动");
    label.textColor = UIColor.whiteColor;
    label.backgroundColor = SQHexColor(@"#000000", 0.4);
    label.textAlignment = NSTextAlignmentCenter;
    label.layer.cornerRadius = 4;
    label.font = FONT_BOLD(16);
    label.layer.masksToBounds = YES;
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(170);
        make.height.mas_equalTo(32);
        make.right.equalTo(self.mas_right).offset(-15);
        make.bottom.equalTo(self.headerView.mas_bottom).offset(-70);
    }];
    
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = UIColor.blackColor;
    bgView.layer.cornerRadius = 12;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.top.equalTo(self.headerView.mas_bottom).offset(-12);
    }];
    
    UIImageView * message = [[UIImageView alloc]init];
    message.image = SQGetImage(@"图标");
    message.contentMode = UIViewContentModeScaleAspectFit;
    [bgView addSubview:message];
    [message mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(38);
        make.height.mas_equalTo(30);
        make.top.equalTo(bgView).offset(18);
        make.right.equalTo(bgView.mas_right).offset(-15);
    }];
    
    [self addSubview:self.messageBtn];
    [self.messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(154);
        make.bottom.equalTo(self.headerView.mas_bottom).offset(38);
    }];
    [bgView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView).offset(15);
        make.top.equalTo(bgView).offset(16);
        make.height.mas_equalTo(24);
    }];
    [bgView addSubview:self.gender];
    [self.gender mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(8);
        make.centerY.equalTo(self.nameLabel);
        make.size.mas_equalTo(18);
    }];
    
    [bgView addSubview:self.ageLabel];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView).offset(15);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(12);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(45);
    }];
    
    [bgView addSubview:self.heightLabel];
    [self.heightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(8);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(12);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(55);
    }];
    
    [bgView addSubview:self.tizhongLabel];
    [self.tizhongLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.heightLabel.mas_right).offset(8);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(12);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(45);
    }];
    
    [bgView addSubview:self.subtitLabel];
    [self.subtitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView).offset(15);
        make.top.equalTo(self.ageLabel.mas_bottom).offset(12);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(SCREEN_WIDETH-30);
    }];
    
    UIView * oneView = [[UIView alloc]init];
    oneView.layer.cornerRadius = 8;
    oneView.layer.masksToBounds= YES;
    oneView.backgroundColor = SQColor(@"#3A383A");
    [bgView addSubview:oneView];
    [oneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bgView);
        make.width.mas_equalTo(SCREEN_WIDETH-30);
        make.top.equalTo(self.subtitLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(120);
    }];
    UILabel * oneLabel= [[UILabel alloc]init];
    oneLabel.text = SQNSLocalString(@"人物介绍");
    oneLabel.textColor = SQColor(@"#F9DA8D");
    oneLabel.font = FONT_BOLD(16);
    [oneView addSubview:oneLabel];
    [oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(oneView).offset(12);
        make.height.mas_equalTo(16);
    }];
    
    [oneView addSubview:self.aboutLabel];
    [self.aboutLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(oneView).insets(UIEdgeInsetsMake(36, 12, 12, 12));
    }];
    
    UIView * towView = [[UIView alloc]init];
    towView.layer.cornerRadius = 8;
    towView.layer.masksToBounds= YES;
    towView.backgroundColor = SQColor(@"#3A383A");
    [bgView addSubview:towView];
    [towView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bgView);
        make.width.mas_equalTo(SCREEN_WIDETH-30);
        make.top.equalTo(oneView.mas_bottom).offset(16);
        make.height.mas_equalTo(136);
    }];
    UILabel * towLabel= [[UILabel alloc]init];
    towLabel.text = SQNSLocalString(@"人物相册");
    towLabel.textColor = SQColor(@"#F9DA8D");
    towLabel.font = FONT_BOLD(16);
    [towView addSubview:towLabel];
    [towLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(towView).offset(12);
        make.height.mas_equalTo(16);
    }];
    UILabel * towlabel2 = [[UILabel alloc]init];
    towlabel2.text = SQNSLocalString(@"（解锁可替换封面）");
    towlabel2.textColor = SQColor(@"#E5E5E5");
    towlabel2.font = FONT_MEDIUM(12);
    [towView addSubview:towlabel2];
    [towlabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(towLabel.mas_bottom);
        make.left.equalTo(towLabel.mas_right).offset(8);
        make.height.mas_equalTo(16);
    }];
    self.collectionView.alwaysBounceHorizontal = NO;
    [self.collectionView registerClass:[ProfileCollectionViewCell class] forCellWithReuseIdentifier:@"ProfileCollectionViewCell"];
    [towView addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(towView).insets(UIEdgeInsetsMake(40, 12, 12, 12));
    }];
}
- (void)setModel:(PeopleModel *)model{
    _model = model;
    [self.headerView sd_setImageWithURL:SQURLImage(model.cover)];
    self.nameLabel.text = model.name;
    self.ageLabel.text = [NSString stringWithFormat:@"%@%@",model.age,SQNSLocalString(@"岁")];
    self.heightLabel.text =[NSString stringWithFormat:@"%@cm",model.height];
    self.tizhongLabel.text =[NSString stringWithFormat:@"%@kg",model.weight];
    self.subtitLabel.text = model.tags;
    if ([model.gender isEqualToString:@"0"]) {
        //男
        self.gender.image = SQGetImage(@"男");
    } else {
        //女
        self.gender.image = SQGetImage(@"女");
    }
    self.aboutLabel.text = model.remark;
    [self.jsonArray removeAllObjects];
    [self.jsonArray addObjectsFromArray:model.photoArray];
    [self.collectionView reloadData];
}

#pragma mark UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.jsonArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
    ProfileCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ProfileCollectionViewCell" forIndexPath:indexPath];
    cell.model = [self.jsonArray objectAtIndex:indexPath.item];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(80, 80);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 12;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    ZSModel * model = [self.jsonArray objectAtIndex:indexPath.item];
    if (model.isLock) {
        [self SQ_popsuoView:model];
    } else {
         //跳转查看页面
        PeoplePhotoViewController * vc = [[PeoplePhotoViewController alloc]init];
        vc.model = self.model;
        vc.seletedModel = model;
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }
  
}
-(void)SQ_popsuoView:(ZSModel*)model{
    JieSuoView * vc = [[JieSuoView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT)];
    vc.model = model;
    LSTPopView * pop = [LSTPopView initWithCustomView:vc
                                           parentView:nil
                                             popStyle:LSTPopStyleFade dismissStyle:LSTDismissStyleFade];
    pop.hemStyle = LSTHemStyleCenter;
   
    [pop pop];
    LSTPopViewWK(pop)
    [vc.guanbi setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [wk_pop dismiss];
    }];
    WS(weakSelf);
    [vc setJiesuoBlock:^{
        [wk_pop dismiss];
        model.isLock = NO;
        [weakSelf.collectionView reloadData];
    }];
}


- (UIImageView *)headerView{
    if (!_headerView) {
        _headerView = [[UIImageView alloc]init];
        _headerView.clipsToBounds = YES;
        _headerView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _headerView;
}
- (SQCustomButton *)messageBtn{
    if (!_messageBtn) {
        _messageBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(80, 70) midmargin:0];
        _messageBtn.image = SQGetImage(@"猫咪");
    }
    return  _messageBtn;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_BOLD(18);
        _nameLabel.textColor =  SQColor(@"#FFFFFF");
        _nameLabel.backgroundColor = UIColor.clearColor;
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLabel;
}
- (UIImageView *)gender{
    if (!_gender) {
        _gender = [[UIImageView alloc]init];
        _gender.image = SQGetImage(@"性别");
    }
    return  _gender;
}
- (UILabel *)ageLabel{
    if (!_ageLabel) {
        _ageLabel = [[UILabel alloc]init];
        _ageLabel.backgroundColor = SQHexColor(@"#ffffff", 0.24);
        _ageLabel.layer.cornerRadius = 8;
        _ageLabel.layer.masksToBounds= YES;
        _ageLabel.textColor = SQColor(@"#FFFFFF");
        _ageLabel.font = FONT_MEDIUM(12);
        _ageLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _ageLabel;
}
- (UILabel *)heightLabel{
    if (!_heightLabel) {
        _heightLabel = [[UILabel alloc]init];
        _heightLabel.backgroundColor = SQHexColor(@"#ffffff", 0.24);
        _heightLabel.layer.cornerRadius = 8;
        _heightLabel.layer.masksToBounds= YES;
        _heightLabel.textColor = SQColor(@"#FFFFFF");
        _heightLabel.font = FONT_MEDIUM(12);
        _heightLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _heightLabel;
}
- (UILabel *)tizhongLabel{
    if (!_tizhongLabel) {
        _tizhongLabel = [[UILabel alloc]init];
        _tizhongLabel.backgroundColor = SQHexColor(@"#ffffff", 0.24);
        _tizhongLabel.layer.cornerRadius = 8;
        _tizhongLabel.layer.masksToBounds= YES;
        _tizhongLabel.textColor = SQColor(@"#FFFFFF");
        _tizhongLabel.font = FONT_MEDIUM(12);
        _tizhongLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _tizhongLabel;
}
- (UILabel *)subtitLabel{
    if (!_subtitLabel) {
        _subtitLabel = [[UILabel alloc]init];
        _subtitLabel.textColor = SQColor(@"#FFFFFF");
        _subtitLabel.font = FONT_MEDIUM(14);
    }
    return _subtitLabel;
}
- (UILabel *)aboutLabel{
    if (!_aboutLabel) {
        _aboutLabel = [[UILabel alloc]init];
        _aboutLabel.textColor = SQColor(@"#DBDBDB");
        _aboutLabel.font = FONT_MEDIUM(14);
        _aboutLabel.numberOfLines = 0;
    }
    return _aboutLabel;
}

- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.userInteractionEnabled = YES;
        _collectionView.backgroundColor = [UIColor clearColor];
       
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    }
    return _collectionView;
}

-(NSMutableArray*)jsonArray
{
    if (!_jsonArray) {
        _jsonArray = [[NSMutableArray alloc]init];
    }
    return _jsonArray;
}
 
@end
